package git.soulbgm.mapreduce.reduceJoin;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author SoulBGM
 * @date 2021/12/1 22:56
 */
public class TableBean implements WritableComparable<TableBean> {

    private Long id;
    private String pid;
    private Integer amount;
    private String pname;
    private String tableName;

    public TableBean() {
        super();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public Integer getAmount() {
        return amount;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public String getPname() {
        return pname;
    }

    public void setPname(String pname) {
        this.pname = pname;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(id);
        out.writeUTF(pid);
        out.writeInt(amount);
        out.writeUTF(pname);
        out.writeUTF(tableName);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        id = in.readLong();
        pid = in.readUTF();
        amount = in.readInt();
        pname = in.readUTF();
        tableName = in.readUTF();
    }

    @Override
    public String toString() {
        return id + "    " +
               pname + "    " +
               amount;
    }

    @Override
    public int compareTo(TableBean o) {
        if (this.id > o.id) {
            return -1;
        } else if (this.id < o.id) {
            return 1;
        } else {
            return 0;
        }
    }
}
